package com.ailesson.user.controller;

import java.util.Arrays;
import java.util.List;

import com.ailesson.user.dto.UserInfoSimpleDto;
import com.ailesson.user.model.reply.UserInfoReply;
import com.ailesson.user.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ailesson.user.model.req.UserInfoReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.ailesson.user.model.req.UserInfoQueryReq;
import com.ailesson.common.reply.PageResult;
import com.ailesson.common.reply.R;



/**
 * 用户表
 *
 * @author mac
 * @email mac@gmail.com
 * @date 2024-09-28 20:21:48
 */
@Tag(name = "用户模块")
@RestController
@RequestMapping("/admin/user/userinfo")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 列表
     */
    @PostMapping("/list")
    @Operation(summary = "列表")
    @Parameter(name = "params", in = ParameterIn.DEFAULT, description = "查询参数")
   // @RequiresPermissions("user:userinfo:list")
    public R list(@RequestBody UserInfoQueryReq params){
        PageResult page = userInfoService.queryPage(params);

        return R.success(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @Operation(summary = "获取信息")
    @Parameter(name = "id",in = ParameterIn.PATH, description = "ID")
   // @RequiresPermissions("user:userinfo:info")
    public R info(@PathVariable("id") Long id){
		UserInfoReply userInfo = userInfoService.info(id);

         return R.success(userInfo);
    }

    /**
     * 批量获取用户简单信息
     */
    @PostMapping("/info/batch-simple")
    @Operation(summary = "批量获取用户简单信息")
    @Parameter(name = "ids",in = ParameterIn.QUERY, description = "ids")
    // @RequiresPermissions("user:userinfo:info")
    public R batchSimple(@RequestBody List<Long> ids){
        List<UserInfoSimpleDto> list = userInfoService.batchSimple(ids);

        return R.success(list);
    }


    /**
     * 保存
     */
    @PostMapping("/add")
    @Operation(summary = "添加")
    @Parameter(name = "teacher",in = ParameterIn.QUERY, description = "添加信息")
    //@RequiresPermissions("user:userinfo:save")
    public R add(@RequestBody UserInfoReq userInfo){
		userInfoService.add(userInfo);

        return R.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @Operation(summary = "更新")
    @Parameter(name = "teacher",in = ParameterIn.QUERY, description = "更新信息")
    //@RequiresPermissions("user:userinfo:update")
    public R update(@RequestBody UserInfoReq userInfo){
		userInfoService.update(userInfo);

        return R.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除")
    @Parameter(name = "ids",in = ParameterIn.QUERY, description = "删除主键ids")
    //@RequiresPermissions("user:userinfo:delete")
    public R delete(@RequestBody Long[] ids){
		userInfoService.removeByIds(Arrays.asList(ids));

        return R.success();
    }

}
